#include "RenderHelper.h"


int RenderHelper::viewX = 0;
int RenderHelper::viewY = 0;
int RenderHelper::worldsEndX = 0;
int RenderHelper::worldsEndY = 0;


RenderHelper::RenderHelper(void)
{
	RenderHelper::viewX = 0;
	RenderHelper::viewY = 0;
	RenderHelper::worldsEndX = 0;
	RenderHelper::worldsEndY= 0;
}

RenderHelper::~RenderHelper(void)
{
}

void RenderHelper::RenderBitmap(HDC buffer, HANDLE image, int x, int y, int width, int height){
	
	if(!(x + width - RenderHelper::viewX < 0 || y + height - RenderHelper::viewY < 0 || x - RenderHelper::viewX > 800 || y - RenderHelper::viewY > 600)){
		RECT rect;
		rect.right = width;
		rect.bottom = height;
		rect.left = x - RenderHelper::viewX;
		rect.top = y - RenderHelper::viewY;



		BITMAP bitmap;
		SIZE imgSize;
		GetObject(image, sizeof(BITMAP), &bitmap);

		imgSize.cx = bitmap.bmWidth;
		imgSize.cy = bitmap.bmHeight;

		HDC hImageDC = CreateCompatibleDC(buffer);

		SelectObject(hImageDC, image);
		

		TransparentBlt(buffer, rect.left,rect.top, rect.right, rect.bottom, hImageDC, 0, 0,width,height, RGB(255,0,255));

		DeleteDC(hImageDC);
	}

}

void RenderHelper::RenderMenu(HDC buffer, HANDLE image, int x, int y, int width, int height){
	
		RECT rect;
		rect.right = width;
		rect.bottom = height;
		rect.left = x;
		rect.top = y;

		BITMAP bitmap;
		SIZE imgSize;
		GetObject(image, sizeof(BITMAP), &bitmap);

		imgSize.cx = bitmap.bmWidth;
		imgSize.cy = bitmap.bmHeight;

		HDC hImageDC = CreateCompatibleDC(buffer);

		SelectObject(hImageDC, image);
		
		TransparentBlt(buffer, rect.left,rect.top, rect.right, rect.bottom, hImageDC, 0, 0,width,height, RGB(255,0,255));

		DeleteDC(hImageDC);
}

void RenderHelper::SetViewPoint(int x, int y){
	
	if(x< 0 ){
		RenderHelper::viewX = 0;
	}
	else if(x>= RenderHelper::worldsEndX){
		RenderHelper::viewX = RenderHelper::worldsEndX;
	}
	else{
		RenderHelper::viewX = x;
	}
	if(y < 0){
		RenderHelper::viewY = 0;
	}
	else if(y >= RenderHelper::worldsEndY){
		RenderHelper::viewY = RenderHelper::worldsEndY;
	}
	else{
		RenderHelper::viewY = y;
	}
}